<template>
  <van-picker
    title="标题"
    show-toolbar
    :columns="columns"
    :default-index="gender"
    @confirm="submit"
    @cancel="$emit('close')"
  />
</template>
<script>
import { updateUserProfile } from "@/api/user";
export default {
  data() {
    return {
      columns: ["男", "女"]
    };
  },
  props: ["gender"],
  methods: {
    async submit(val, index) {
      try {
        await updateUserProfile({
          gender: index
        });
        this.$emit("close", index);
      } catch (error) {
        this.$toast.fail("更新性别失败");
      }
    }
  }
};
</script>
<style lang="less" scoped></style>
